import java.util.Scanner;

public class NGuessNumber {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        //生成一个答案。创建一个单次游戏循环
        int d;
        while (true) {
            System.out.println("请输入数字,你可以猜三次");


            int answer;


            answer = (int) (Math.random() * 10);
            for (d = 0; d < 3; d++) {
                int k = scanner.nextInt();
                if (answer == k) {
                    System.out.println("玩家获胜,单次游戏循环结束");

                    System.exit(0);
                } else if (d == 2) {
                    System.out.println("答案为："+answer+"游戏结束");

                    break;
                }
            }

            if (d == 2) {
                System.out.println("是否决定再玩一局请输入y/n");
                while (true) {
                    String kd = scanner.nextLine();
                    if (kd.equals("y")) {
                        break;
                    } else if (kd.equals("n")) {
                        System.exit(0);
                    } else {
                        System.out.println("y/n");
                    }
                }

            }
        }

    }
    static int []answerList=new int[4];
    static int []answerList2inp=new int[4];
    static int two,one;
    public static int[] generateAnswer() {


        for (int a=0;a<4;a++) {
            int answer = (int) (Math.random() * 10);
            if (a>0)
                if (answer!=answerList[a-1])
                    answerList [a]=answer;

        }
        return answerList;
    }

    static int []getPlayerInput(){//用户输入的4个数
        Scanner scanner=new Scanner(System.in);
        for (int a=0;a<4;a++) {
            int answer = scanner.nextInt();
            if (a>0)
                if (answer!=answerList2inp[a-1])
                    answerList2inp [a]=answer;

        }
        return answerList2inp;
    }

    public static String compareGuessAnswer() {
        one = 0;
         two = 0;

        for (int i = 0; i < answerList.length; i++) {
            for (int j = 0; j < answerList2inp.length; j++) {
                if (i != j) {
                    if (answerList[i] == answerList2inp[j]) {
                        one++;
                    }
                } else {
                    if (answerList[i] == answerList2inp[j]) {
                        two++;
                    }
                }
            }
        }
        System.out.println(two + "个对" + one + "个位置错的数字对的");

        return two + "个对" + one + "个位置错的数字对的";   }

    public static boolean isWin() {
        if(two==4) {
            return true;
        }else
         return false;
    }
}
